package br.com.klis.batendoumabola.server.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	public static Date zerarTime(Date data){
		if (data == null){
			return null;
		}
		Calendar calendar = Calendar.getInstance();
    	calendar.setTime(data);
    	return zerarTime(calendar);
	}
	
	public static Date zerarTime(Calendar calendar){
		calendar.set(Calendar.HOUR_OF_DAY,0);
    	calendar.set(Calendar.MINUTE, 0);
    	calendar.set(Calendar.SECOND, 0);
    	calendar.set(Calendar.MILLISECOND, 0);
		return calendar.getTime();
	}
	
	public static String convertDateToString(Date data){
		if (data == null){
			return null;
		}
		DateFormat dt = new SimpleDateFormat("yyyyMMdd");
		return dt.format(data);
	}
	
	public static String convertDateTimeToString(Date data){
		if (data == null){
			return null;
		}
		DateFormat dt = new SimpleDateFormat("yyyyMMdd hh:mm:ss");
		return dt.format(data);
	}
	
	/*public static Date convertStringToDate(String data){
		if (data == null){
			return null;
		}
		String ano = data.substring(0, 4);
		String mes = data.substring(4, 6);
		String dia = data.substring(6, 8);
		
		Calendar calendar = Calendar.getInstance();
    	calendar.set(Calendar.YEAR,new Integer(ano));
    	calendar.set(Calendar.MONTH, new Integer(mes)-1);
    	calendar.set(Calendar.DAY_OF_MONTH, new Integer(dia));
    	
    	return zerarTime(calendar.getTime());
	}*/
}
